package logic

import (
	"context"
	"month2/C/rpc_C/model/mysql"

	"month2/C/rpc_C/internal/svc"
	"month2/C/rpc_C/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsInfoLogic {
	return &GoodsInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsInfoLogic) GoodsInfo(in *order.GoodsInfoRequest) (*order.GoodsInfoResponse, error) {
	var goods []*mysql.Goods1
	mysql.DB.Where("id=?", in.GoodsId).Find(&goods)
	var info []*order.GoodsInfo
	for _, good := range goods {
		goodsInfo := order.GoodsInfo{
			GoodsName:  good.GoodsName,
			GoodsPrice: float32(good.GoodsPrice),
			GoodsNum:   int64(good.GoodsNum),
			GoodsImg:   good.GoodsImg,
			LikeCount:  int64(good.LikeCount),
			GoodsType:  int64(good.GoodsType),
		}
		info = append(info, &goodsInfo)
	}
	return &order.GoodsInfoResponse{Info: info}, nil
}
